package br.com.searchpeople.activity;

import br.com.searchpeople.R;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

public class ShowPostActivity extends Activity{
	
	private TextView name;
	private TextView description;
	private TextView city;
	private TextView state;
	private TextView country;
	private TextView email;
	private TextView phone;
	private ImageView imagePost;
	private Button compartilhar;
	private Button ligar;
	private Button sms;
	private String phoneCallSMS;
	@Override
	protected void onCreate(Bundle savedInstanceState)  {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_showpost);
		
		name = (TextView) findViewById(R.id.textview_showname);
		description = (TextView) findViewById(R.id.textview_showdescription);
		city = (TextView) findViewById(R.id.textview_showcity);
		state = (TextView) findViewById(R.id.textview_showstate);
		country = (TextView) findViewById(R.id.textview_showcountry);
		email = (TextView) findViewById(R.id.textview_showemail);
		phone = (TextView) findViewById(R.id.textview_showphone);
		imagePost = (ImageView) findViewById(R.id.imageview_showpostimage);
		compartilhar = (Button) findViewById(R.id.button_showcompartilhar);
		ligar = (Button) findViewById(R.id.button_showligar);
		sms = (Button) findViewById(R.id.button_showsms);
		
		Intent it = getIntent();
		if (it != null) {
			name.setText(it.getStringExtra("name"));
			description.setText(it.getStringExtra("description"));
			city.setText(it.getStringExtra("city"));
			state.setText(it.getStringExtra("state"));
			country.setText(it.getStringExtra("country"));
			email.setText(email.getText() + it.getStringExtra("email"));
			phone.setText(phone.getText() + it.getStringExtra("phone"));
			phoneCallSMS = it.getStringExtra("phone");
			Bitmap b = null;
			if(getIntent().hasExtra("byteArray")) {
			    ImageView previewThumbnail = new ImageView(this);
			     b = BitmapFactory.decodeByteArray(getIntent().getByteArrayExtra("byteArray"),0,getIntent().getByteArrayExtra("byteArray").length);        
			    previewThumbnail.setImageBitmap(b);
			}
			imagePost.setImageBitmap(b);
		}
		
		
		ligar.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Intent callIntent = new Intent(Intent.ACTION_CALL);
				callIntent.setData(Uri.parse("tel:" + phoneCallSMS));
				startActivity(callIntent);
				
			}
		});
		
		sms.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Intent smsIntent = new Intent(Intent.ACTION_VIEW);
				smsIntent.setType("vnd.android-dir/mms-sms");
				smsIntent.putExtra("address", phoneCallSMS);
				startActivity(smsIntent);
			}
		});
		
	}

}
